using B.S.BaseData.Infrastructure;
using B.S.BaseData.Infrastructure.Implement;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(p =>
{
    p.IncludeXmlComments(AppContext.BaseDirectory + "B.S.BaseData.Read.API.xml", true);
});
builder.Services.AddDbContext<DBContext>(x =>
{
    x.UseSqlServer(builder.Configuration.GetConnectionString("DB"));
});

builder.Services.AddScoped(typeof(IBaseRepository<>),typeof(BaseRepository<>));
builder.Services.AddMediatR(x=>x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));

builder.Services.AddAutoMapper(typeof(MappingProfile));

var app = builder.Build();
app.UseCors(x=>x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
    app.UseSwagger();
    app.UseSwaggerUI();
//}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
